from flask import Flask
from flask_cors import CORS
from api.api import api_bp
from models.models import db

# 初始化 Flask 应用
app = Flask(__name__)
CORS(app)

# 数据库配置
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 初始化数据库
db.init_app(app)

# 注册 Blueprint
app.register_blueprint(api_bp)


# 根路由
@app.route('/', methods=['GET'])
def hello():
    db.create_all()
    return "hello world"


# 启动服务器
if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5001)
